{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Setting up Environment\n",
        "We will use Google Colab as the notebook; however, we will connect it with the local machine's runtime environment for two main reasons: Firstly, compared to the free version of Google Colab, a local machine has more resources (RAM and CPU) for computation. Secondly, it is easier to set up different virtual environments on a local machine. Here are the steps we will follow to set up the overall environment:\n",
        "1. Install Anaconda on the local machine.\n",
        "\n",
        "2. Create a virtual environment.\n",
        "3. Install necessary packages in the virtual environment.\n",
        "4. Configure and Start Jupyter Notebook\n",
        "5. Connect Google Colab with your local runtime environment.\n"
      ],
      "metadata": {
        "id": "78jaxZqVTcL8"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Install Anaconda on the local machine\n",
        "1. Go to the Anaconda download page: https://www.anaconda.com/products/distribution\n",
        "2. Download appropriate version for your computer\n",
        "3. Follow the instructions provided by the installer\n",
        "4. If the installer prompt you to add anaconda in system’s  PATH variable; please do it. This enables you to seamlessly use Anaconda's features from the command line\n",
        "5. Check if installation is successful by typing following command in terminal.\n",
        "\n",
        "\n",
        "```\n",
        "conda --version\n",
        "```\n",
        "\n",
        "\n"
      ],
      "metadata": {
        "id": "gUHRZSoKTr01"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Create a virtual environment.\n",
        "To create a virtual environment in Anaconda via the terminal, follow these steps:\n",
        "1. Open the terminal on your local machine.\n",
        "2. Type the following command and press Enter to create a new virtual environment. In the below code, virtual environment name is torch_learn; and python version is 3.11\n",
        "  ```\n",
        "conda create --name torch_learn python=3.11\n",
        "```\n",
        "3. Once the environment has been created, activate it by typing the following command:\n",
        "```\n",
        "conda activate transformer_learn\n",
        "```\n",
        "4. Install the necessary Package in your environment. Following are requirement for chapter 2. Install based on each chapter.\n",
        "```\n",
        "pip3 install transformers\n",
        "pip3 install datasets\n",
        "pip3 install git+https://github.com/huggingface/diffusers\n",
        "pip3 install accelerate\n",
        "pip3 install ftfy\n",
        "pip3 install tensorboard\n",
        "pip3 install Jinja2\n",
        "```\n",
        "\n",
        "\n",
        "\n"
      ],
      "metadata": {
        "id": "_vM1jIoQUEHn"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Configure and Start Jupyter Notebook\n",
        "Please follow following instructions (https://research.google.com/colaboratory/local-runtimes.html):\n",
        "1. Install and enable the jupyter_http_over_ws jupyter extension (one-time). Please make sure you have activated virtual environment `transformer_learn` before running the command.\n",
        "```\n",
        "pip3 install jupyter_http_over_ws\n",
        "jupyter serverextension enable --py jupyter_http_over_ws\n",
        "```\n",
        "2. Start server and authenticate\n",
        "```\n",
        "jupyter notebook \\\n",
        "  --NotebookApp.allow_origin='https://colab.research.google.com' \\\n",
        "  --port=8888 \\\n",
        "  --NotebookApp.port_retries=0\n",
        "  ```\n",
        "3. After starting the server, it will display a message with a URL that is needed for authentication. Copy the highlighted URL, as you will need to use it in the next step. The screen looks like"
      ],
      "metadata": {
        "id": "BOW3d161VkDU"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "![Screenshot 2023-09-06 at 12.37.49 PM.png]()"
      ],
      "metadata": {
        "id": "dIRCy5M1Wlo-"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "##  Connect Google Colab with your local runtime environment\n",
        "1. Click the \"Connect\" button in colab."
      ],
      "metadata": {
        "id": "-G1QucFkXDBf"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "![Screenshot 2023-09-06 at 12.39.26 PM.png]()"
      ],
      "metadata": {
        "id": "CZIzNW3_XLXw"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "2. Select \"Connect to local runtime...\n",
        "3. A dialog box will appear. Enter the URL you copied from the previous step into the box.\n",
        "4. Click the \"Connect\" button.\n",
        "5. You should now be connected to your local runtime.\n",
        "6. You can check which virtual environment, your Colab is using by typing following command:\n",
        "```\n",
        "import sys\n",
        "print(sys.prefix)\n",
        "```\n",
        "Note: The output was `/Users/premtimsina/opt/anaconda3/envs/transformer_learn`. This means my Colab is using my transformer_learn virtual environment which is installed in my local machine.\n",
        "\n"
      ],
      "metadata": {
        "id": "P1fSkWGHXT35"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "VqY-rQFGTJk4"
      },
      "outputs": [],
      "source": []
    }
  ]
}